#include "Player.h"

#include "Projectile.h"
#include "Liquid.h"
#include "..\Game Objects\Camera.h"
#include "..\Game Objects\PowerUps.h"
#include "..\Game Objects\SpikeObject.h"
#include "..\Game Objects\CrumblingPlatformObject.h"
#include "..\Message Management\MessageID.h"
#include "..\Definitions.h"

#include "..\\Game States\GamePlayState.h"
#include "..\\Game States\GameTimeAttack.h"
#include "..\\Game.h"
#include "..\..\SGD Wrappers\SGD_InputManager.h"
#include "..\..\SGD Wrappers\SGD_GraphicsManager.h"

Player::Player()
{
	// Set Movement/Facing values
	bStanding = true;
	bRunning = bJumping = bAttackLeft
		= bAttackRight = bAttackUp = bAttackDown = bDie = false;
	IsFacingLeft(false);
	PrevDirection(false);

	// Set CrumglingPlatform false
	IsOnCrumblingPlatformObject(false);

	bFacingUp = bFacingDown = false;
	SetAnimation("PlayerIdleRight");

	// Play Game Over Message
	SetPlayGameOver(false);

	SetCurrentHP(100);
	SetIsKilled(false);

	// Set Aura variables and Load Aura Image
	bAuraFlashing = false;
	fAuraFlashingTimer = 0;
	hPlayerAura = GRAPHICS->LoadTexture("Resource/Images/playeraura.png", SGD::Color{ 0, 255, 0 });
	fFadeout = 0;
	spawnLoc = SGD::Point(0.0f, 0.0f);
}

Player::~Player()
{
	GRAPHICS->UnloadTexture(hPlayerAura);
}

int Player::Update(float dt)
{
	///////////////////////////////////////////////
	// Known Bug Fix ID: 09
	// Implemented by: Cliff Baird
	// Disabling wall jump if player is on ground
	///////////////////////////////////////////////
	if (IsOnGround())
		IsOnWall(false);
	///////////////////////////////////////////////
	// End Known Bug Fix ID: 09
	///////////////////////////////////////////////

	if (IsOnWall())
	{
		SetWallTime(GetWallTime() - dt);
		if (GetWallTime() <= 0.0f)
			IsOnWall(false);
	}

	if (!IsAttacking())
		bFacingDown = bFacingUp = false;

	// Create local pointers to objects
	Camera* camera = Camera::GetInstance();
	SGD::InputManager* Input = SGD::InputManager::GetInstance();

	// Set Jumping to false
	IsJumping(false);

	if (GetPosition().y >= GAME->GetBottomOfLevel() + 160)
	{
		if (GAME->GetPlayerLives() <= 0)
		{
			return 2; // Tells Gameplay state to start Lose transition
		}
		else
		{
			return 1; // Tells Gameplay State to start Death transition
		}
	}

	if (GetCurrentHP() <= 0) // Dying
	{
		if (GetCurrentAnimationName() != "PlayerDeath")
			SetAnimation("PlayerDeath");
		// Allow time for Game Over To Show
		if (GAME->GetPlayerLives() <= 0 && !GetAnimation()->IsPlaying())
		{
			return 2; // Tells Gameplay state to start Lose transition
		}
		else if (!GetAnimation()->IsPlaying())
		{
			return 1; // Tells Gameplay State to start Death transition
		}
		else
		{
			SetVelocity(SGD::Vector(0.0f, 0.0f));
			SetAcceleration(SGD::Vector(0.0f, 0.0f));
			GameObject::Update(dt);
			if (GAME->GetPlayerLives() == 1)
				SetPlayGameOver(true);
			return 0; // Play death animation
		}
	}

	// Reset Aura's timer
	if (fAuraFlashingTimer > .5f)
		fAuraFlashingTimer = 0;
	// Update Aura's timer
	fAuraFlashingTimer += dt;

	// Testing Health
	if (Input->IsKeyPressed(SGD::Key::K) && DEBUG)
	{
		SetCurrentHP(GetCurrentHP() - 50);

		// Activate Emitter
		if (GetEmitters().size() > 0)
		{
			GetEmitters()[0]->SetPlay(true);
			SetParticleTimer(1.0f);
		}
	}

	// Attack
	if (!IsAttacking() && KEYATTACK)
	{
		IsAttacking(true);
	}

	// Jump
	if (IsOnGround() && !IsJumping() && KEYJUMP || IsOnCrumblingPlatformObject() && KEYJUMP)
	{
		GAME->PlayPlayerJumpAudio();


		// Set Not on Crumbling Platform Object if was
		if (IsOnCrumblingPlatformObject())
		{
			IsOnGround(false);
			IsOnCrumblingPlatformObject(false);
		}

		// Set Jumping
		IsJumping(true);

		if (!IsFacingLeft())
			SetAnimation("PlayerJumpRight");
		else
			SetAnimation("PlayerJumpLeft");
	}
	else if (IsOnWall() && !IsOnGround() && !IsJumping() && KEYJUMP)
	{
		GAME->PlayPlayerJumpAudio();

		// Set Jumping
		IsJumping(true);

		if (!IsFacingLeft())
			SetAnimation("PlayerJumpRight");
		else
			SetAnimation("PlayerJumpLeft");
	}

	// Move character based on player input
	if (KEYLEFT) 		// Left
	{
		if (!IsOnWall())
			MoveLeft();
	}
	else if (KEYRIGHT) 	// Right
	{
		if (!IsOnWall())
			MoveRight();
	}
	else																							// No input
	{
		NoInput();
	}

	if (KEYUP)
	{
		// Set Facing values
		bFacingUp = true;
		bFacingDown = false;
	}
	else if (KEYDOWN)
	{
		// Set Facing values
		bFacingDown = true;
		bFacingUp = false;
	}

	if (IsJumping())
	{
		if (IsOnWall() && IsOnLeftWall())
		{
			SetVelocity(SGD::Vector(700, -700));
			//SetAcceleration(SGD::Vector(6500, -4000.0f));				// Increase Velocity away from wall and up
		}
		else if (IsOnWall() && !IsOnLeftWall())
		{
			SetVelocity(SGD::Vector(-700, -700));
			//SetAcceleration(SGD::Vector(-6500, -4000.0f));				// Increase Velocity away from wall and up
		}
		else
		{
			SetVelocity(SGD::Vector(GetVelocity().x, -750));
			//SetAcceleration(SGD::Vector(GetAcceleration().x, -4000.0f));		// Increase Velocity in -Y direction and set X velocity to stored amount
		}
		IsOnGround(false);		// No longer on ground
		IsOnWall(false);		// No longer on wall
		IsOnCrumblingPlatformObject(false); // No longer on crumbling platform
	}

	if (IsAttacking())
		Attack(dt);

	AdjustCamera();

	if (IsOnGround())
	{
		SetAcceleration(SGD::Vector{ GetAcceleration().x, 0.0f });
		SetVelocity(SGD::Vector{ GetVelocity().x, 0.0f });

		if (spawnLoc == SGD::Point(0.0f, 0.0f))
		{
			spawnLoc = GetPosition();
		}
	}

	//////////////////////////////////////////////////////
	// Found Bug Fix ID: 11
	// Implemented by: Cliff Baird
	// Move the emitter up by 48 pixels
	//////////////////////////////////////////////////////
	SGD::Point emit = GetPosition();
	emit.y -= 48.0f;
	if (GetEmitters().size() > 0)
		GetEmitters()[0]->SetPosition(emit);
	//////////////////////////////////////////////////////
	// End Found Bug Fix Id: 11
	//////////////////////////////////////////////////////

	// Call Entities Update
	Entity::Update(dt);

	return 0;
}

void Player::Render()
{
	// Set camera position
	Camera* camera = Camera::GetInstance();
	SGD::Point offset = GetPosition();
	offset.x -= camera->GetPosition().x;
	offset.y -= camera->GetPosition().y;

	if (GAME->GetPlayer()->GetCurrentHP() > 0)
	{
		// Draw Aura
		// Calculate Color by current health divided by max health
		float fPercent = (float)GetCurrentHP() / (float)GetMaxHP();
		unsigned char ucGreen = (unsigned char)(255 * fPercent);
		unsigned char ucRed = 0;
		if (fPercent <= 1.0f)
			ucRed = 255 - ucGreen;
		// Check if Aura should be flashing
		if (fPercent <= .3f)
			bAuraFlashing = true;
		// Chec if Aura should stop flashing
		if (fPercent > .3f)
			bAuraFlashing = false;
		// Draw Solid Aura
		if (!bAuraFlashing)
			GRAPHICS->DrawTexture(hPlayerAura, SGD::Point(offset.x - GetSize().width / 1.5f, offset.y - GetSize().height), 0.0f, SGD::Vector{},
			SGD::Color{ 220, ucRed, ucGreen, 0 });
		// Draw Flashing Aura
		if (bAuraFlashing && fAuraFlashingTimer >= .15f)
		{
			GRAPHICS->DrawTexture(hPlayerAura, SGD::Point(offset.x - GetSize().width / 1.5f, offset.y - GetSize().height), 0.0f, SGD::Vector{},
				SGD::Color{ 220, ucRed, ucGreen, 0 });
		}
	}

	// Draw Attack Arch
	if (IsAttacking())
	{
		SGD::Rectangle sourceRect = { 434.0f, 204.0f, 469.0f, 297.0f };

		// Set Scale to allow flipping
		SGD::Size scale = { 1.0f, 1.0f };
		// Facing Left
		if (IsFacingLeft())
			scale.width = -1;

		GRAPHICS->DrawTextureSection(GAME->hPlayerImage,
			GetArchDrawPointLoc(), sourceRect, 0.0f,
			{}, {}, scale);
	}

	// Test Draw position
	if (DEBUG)
		GRAPHICS->DrawRectangle(SGD::Rectangle(offset.x, offset.y, offset.x + 1, offset.y + 1), { 255, 0, 0 }, { 255, 0, 0 });

	GameObject::Render();
}


void Player::HandleCollision(const GameObject* collision)
{
	if (collision->GetID() == GameObject::ObjectID::PROJECTILE)
	{
		const Projectile* p = dynamic_cast<const Projectile*>(collision);
		SetCurrentHP(GetCurrentHP() - p->GetDamage());

		GAME->PlayEnemyAttackAudio();

		// Activate Emitter
		if (GetEmitters().size() > 0)
		{
			GetEmitters()[0]->SetPlay(true);
			SetParticleTimer(1.0f);
		}

		return;
	}
	// Check if collision is Liquid
	else if (collision->GetID() == LIQUID)
	{
		const Liquid* liquid = dynamic_cast<const Liquid*>(collision);
		if (liquid->GetDamageTimer() <= 0.0f)
			SetCurrentHP(GetCurrentHP() - liquid->GetDamage());

		if (GetVelocity().x > 100.0f)
			SetVelocity(SGD::Vector(100.0f, GetVelocity().y));
		else if (GetVelocity().x < -100.0f)
			SetVelocity(SGD::Vector(-100.0f, GetVelocity().y));
		if (GetVelocity().y > 100.0f)
			SetVelocity(SGD::Vector(GetVelocity().x, 100.0f));
		else if (GetVelocity().y < -500.0f)
			SetVelocity(SGD::Vector(GetVelocity().x, -500.0f));
	}
	// Check if collision is Check Point
	else if (collision->GetID() == GameObject::ObjectID::CHECK_POINT)
	{
		// Do Nothing
		return;
	}
	// Check if crumbling platform
	else if (collision->GetID() == GameObject::ObjectID::CRUMBLING_PLATFORM)
	{
		//IsOnCrumblingPlatformObject(true);

		// Leave and Do Nothing
		return;
	}
	// Check if a Wall Trigger
	else if (collision->GetID() == GameObject::ObjectID::WALL_TRIGGER_OBJECT)
	{
		// Check if left
		if (GetPosition().x < collision->GetPosition().x + collision->GetLeftCollisionOffset())
			SetPosition(SGD::Point{ collision->GetPosition().x + collision->GetLeftCollisionOffset() - GetRightCollisionOffset(), GetPosition().y });
		// Check if right
		else if (GetPosition().x > collision->GetPosition().x)
			SetPosition(SGD::Point{ collision->GetPosition().x + collision->GetRightCollisionOffset() + GetLeftCollisionOffset(), GetPosition().y });
		// Stop Velocity on x axis
		SetVelocity(SGD::Vector{ 0.0f, GetVelocity().y });

		// Leave
		return;
	}
	// Check if spike
	else if (collision->GetID() == GameObject::ObjectID::SPIKE)
	{
		if (GetInvulnerableTimer() <= 0)
		{
			SetInvulnerableTimer(0.5f);
			SetCurrentHP(GetCurrentHP() - ((SpikeObject*)collision)->GetDamage());
		}

		// Activate Emitter
		if (GetEmitters().size() > 0)
		{
			GetEmitters()[0]->SetPlay(true);
			SetParticleTimer(1.0f);
		}
		// Leave
		return;
	}
	// Check if springboard
	else if (collision->GetID() == GameObject::ObjectID::SPRINGBOARD)
	{
		if (!IsOnGround())
		{
			GAME->PlaySpringboardAudio();
			SetAcceleration(SGD::Vector(GetAcceleration().x, -1800));
			SetVelocity(SGD::Vector(GetVelocity().x, -450.0f));
		}
		// Leave
		return;
	}
	// Check if enemy
	else if (collision->GetID() == MELEE || collision->GetID() == RANGED || collision->GetID() == QUDZU || collision->GetID() == LOCKJAW || collision->GetID() == PAPABEAR)
	{
		SGD::Rectangle currentRect = GetCollisionRect();
		SGD::Rectangle collisionRect = collision->GetCollisionRect();
		float currentLeft = currentRect.left;
		float currentRight = currentRect.right;
		float collisionLeft = collisionRect.left;
		float collisionRight = collisionRect.right;
		if (currentRight >= collisionLeft && currentLeft < collisionLeft)
			SetPosition(SGD::Point(collisionLeft - GetRightCollisionOffset() + CAMERA->GetPosition().x, GetPosition().y));
		else if (currentLeft <= collisionRight && currentRight > collisionRight)
			SetPosition(SGD::Point(collisionRight + GetLeftCollisionOffset() + CAMERA->GetPosition().x, GetPosition().y));

		SetVelocity(SGD::Vector{ 0.0f, GetVelocity().y });
		SetAcceleration(SGD::Vector{ 0.0f, GetAcceleration().y });
	}
}

void Player::HandleAttackCollision(const GameObject* collision)
{
	if (!IsInvulnerable())
	{
		Entity::HandleAttackCollision(collision);

		// Activate Emitter
		if (GetEmitters().size() > 0)
		{
			GetEmitters()[0]->SetPlay(true);
			SetParticleTimer(1.0f);
		}
	}
}

SGD::Point Player::GetArchDrawPointLoc()
{
	return archDrawPointLoc;
}

void Player::SetArchDrawPointLoc(SGD::Point drawPoint)
{
	archDrawPointLoc = drawPoint;
}

bool Player::IsOnCrumblingPlatformObject()
{
	return bOnCrumbPlatform;
}

void Player::IsOnCrumblingPlatformObject(bool crumbling)
{
	bOnCrumbPlatform = crumbling;
}

bool Player::GetPlayGameOver()
{
	return bPlayGameOver;
}

void Player::SetPlayGameOver(bool bPlay)
{
	bPlayGameOver = bPlay;
}

void Player::MoveLeft()
{
	if (GetVelocity().x > 110)
		SetAcceleration(SGD::Vector(-(GetVelocity().x * 5.0f), GetAcceleration().y));
	//////////////////////////////////////////////////////
	// Known Bug Fix ID: 07
	// Implemented by: Cliff Baird
	// Increase velocity for one frame if not moving to
	//  compensate for wall collision
	//////////////////////////////////////////////////////
	else if (GetVelocity().x == 0.0f && !IsOnGround())
	{
		SetVelocity(SGD::Vector(-100.0f, GetVelocity().y));
		SetAcceleration(SGD::Vector(-600.0f, GetAcceleration().y));
	}
	//////////////////////////////////////////////////////
	// End Bug Fix ID: 07
	//////////////////////////////////////////////////////
	else
		SetAcceleration(SGD::Vector(-600.0f, GetAcceleration().y));

	// Reset Attack Rect if changed direction
	if (!PrevDirection())
	{
		SetAttackRect(SGD::Rectangle{ -1, -1, -1, -1 });
		SetArchDrawPointLoc(SGD::Point{ -20, -20 });
		SetAttackTimer(0.0f);
		IsAttacking(false);
	}

	// Set Movement/Facing values
	IsFacingLeft(true);
	PrevDirection(true);

	// Set Animation
	if (IsOnGround())
	{
		if (GetVelocity().x >= -500 && GetCurrentAnimationName() != "PlayerWalkLeft" && !IsAttacking())
			SetAnimation("PlayerWalkLeft");
		else if (GetVelocity().x <= -500)
		{
			if (GetCurrentAnimationName() != "PlayerRunLeft"  && !IsAttacking())
				SetAnimation("PlayerRunLeft");
		}
	}
	else if (!IsOnGround() && GetCurrentAnimationName() != "PlayerJumpLeft")
	{
		if (GetCurrentAnimationName() == "PlayerJumpRight")
		{
			int frame = GetAnimation()->GetCurrentFrame();
			float time = GetAnimation()->GetFrame().GetCurrentTime();
			SetAnimation("PlayerJumpLeft");
			GetAnimation()->SetCurrentFrame(frame);
			GetAnimation()->GetFrame().SetCurrentTime(time);
		}
		else
			SetAnimation("PlayerJumpLeft");
	}
}

void Player::MoveRight()
{
	if (GetVelocity().x < -110)
		SetAcceleration(SGD::Vector(-(GetVelocity().x * 5.0f), GetAcceleration().y));
	//////////////////////////////////////////////////////
	// Known Bug Fix ID: 07
	// Implemented by: Cliff Baird
	// Increase velocity for one frame if not moving to
	//  compensate for wall collision
	//////////////////////////////////////////////////////
	else if (GetVelocity().x == 0.0f && !IsOnGround())
	{
		SetVelocity(SGD::Vector(100.0f, GetVelocity().y));
		SetAcceleration(SGD::Vector(600.0f, GetAcceleration().y));
	}
	//////////////////////////////////////////////////////
	// End Bug Fix ID: 07
	//////////////////////////////////////////////////////
	else
		SetAcceleration(SGD::Vector(600.0f, GetAcceleration().y));

	// Reset Attack Rect if changed direction
	if (PrevDirection())
	{
		SetAttackRect(SGD::Rectangle{ -1, -1, -1, -1 });
		SetArchDrawPointLoc(SGD::Point{ -20, -20 });
		SetAttackTimer(0.0f);
		IsAttacking(false);
	}

	// Set Movement/Facing values
	IsFacingLeft(false);
	PrevDirection(false);

	if (IsOnGround())
	{
		if (GetVelocity().x <= 500 && GetCurrentAnimationName() != "PlayerWalkRight"  && !IsAttacking())
			SetAnimation("PlayerWalkRight");
		else if (GetVelocity().x >= 500)
		{
			if (GetCurrentAnimationName() != "PlayerRunRight"  && !IsAttacking())
				SetAnimation("PlayerRunRight");
		}
	}
	else if (GetCurrentAnimationName() != "PlayerJumpRight")
	{
		if (GetCurrentAnimationName() == "PlayerJumpLeft")
		{
			int frame = GetAnimation()->GetCurrentFrame();
			float time = GetAnimation()->GetFrame().GetCurrentTime();
			SetAnimation("PlayerJumpRight");
			GetAnimation()->SetCurrentFrame(frame);
			GetAnimation()->GetFrame().SetCurrentTime(time);
		}
		else
			SetAnimation("PlayerJumpRight");
	}
}

void Player::NoInput()
{
	if (GetVelocity().x > -15.0f && GetVelocity().x <= 15.0f)
	{
		SetAcceleration(SGD::Vector(0, GetAcceleration().y));
		SetVelocity(SGD::Vector(0, GetVelocity().y));

		if (IsFacingLeft() && GetCurrentAnimationName() != "PlayerIdleLeft"  && !IsAttacking())
			SetAnimation("PlayerIdleLeft");
		else if (!IsFacingLeft() && GetCurrentAnimationName() != "PlayerIdleRight"  && !IsAttacking())
			SetAnimation("PlayerIdleRight");
	}
	else
	{
		////////////////////////////////////////////////////
		// Found Bug Fix ID: 11
		// Implemented by: Cliff Baird
		// Sets animation to walking or running if
		//  on ground based on current speed
		////////////////////////////////////////////////////
		if (IsOnGround())
		{
			if (!IsFacingLeft() && GetVelocity().x <= 500 && GetCurrentAnimationName() != "PlayerWalkRight"  && !IsAttacking())
				SetAnimation("PlayerWalkRight");
			else if (!IsFacingLeft() && GetVelocity().x >= 500 && GetCurrentAnimationName() != "PlayerRunRight"  && !IsAttacking())
				SetAnimation("PlayerRunRight");
			else if (IsFacingLeft() && GetVelocity().x >= -500 && GetCurrentAnimationName() != "PlayerWalkLeft"  && !IsAttacking())
				SetAnimation("PlayerWalkLeft");
			else if (IsFacingLeft() && GetVelocity().x <= -500 && GetCurrentAnimationName() != "PlayerRunLeft"  && !IsAttacking())
				SetAnimation("PlayerRunLeft");
		}
		/////////////////////////////////////////////////////
		// End Bug Fix ID: 11
		/////////////////////////////////////////////////////
		SetAcceleration(SGD::Vector(-(GetVelocity().x * 2.0f), GetAcceleration().y));
	}
}

void Player::Attack(float dt)
{
	Camera* camera = Camera::GetInstance();
	SetAttackTimer(GetAttackTimer() + dt);
	float time = GetAttackTimer();
	if (GetAttackTimer() >= GetAttackResetTime())
	{
		SetAttackTimer(0.0f);
		SetAttackRect(SGD::Rectangle(-1, -1, -1, -1));
		SetArchDrawPointLoc(SGD::Point{ -20, -20 });

		// Reset up/down facing
		bFacingDown = false;
		bFacingUp = false;
		IsAttacking(false);
	}
	else
	{

		/*if (bFacingDown)
		{
		if (GetCurrentAnimationName() != "PlayerAttackDown")
		SetAnimation("PlayerAttackDown");

		if (GetAttackTimer() < GetAttackResetTime() * 0.05f)
		{
		SGD::Rectangle rect;
		rect.left = GetPosition().x + 20 + camera->GetPosition().x;
		rect.top = GetPosition().y + camera->GetPosition().y;
		rect.right = rect.left + 10 + camera->GetPosition().x;
		rect.bottom = rect.top + 20 + camera->GetPosition().y;
		SetAttackRect(rect);
		}
		else if (GetAttackTimer() < GetAttackResetTime() * 0.1f)
		{
		SGD::Rectangle rect;
		rect.left = GetPosition().x + 20 + camera->GetPosition().x;
		rect.top = GetPosition().y + camera->GetPosition().y;
		rect.right = rect.left + 10 + camera->GetPosition().x;
		rect.bottom = rect.top + 20 + camera->GetPosition().y;
		SetAttackRect(rect);
		}
		else if (GetAttackTimer() < GetAttackResetTime() * 0.2f)
		{
		SGD::Rectangle rect;
		rect.left = GetPosition().x + 20 + camera->GetPosition().x;
		rect.top = GetPosition().y + camera->GetPosition().y;
		rect.right = rect.left + 10 + camera->GetPosition().x;
		rect.bottom = rect.top + 20 + camera->GetPosition().y;
		SetAttackRect(rect);
		}
		else
		{
		SGD::Rectangle rect;
		rect.left = GetPosition().x + 20 + camera->GetPosition().x;
		rect.top = GetPosition().y + camera->GetPosition().y;
		rect.right = rect.left + 10 + camera->GetPosition().x;
		rect.bottom = rect.top + 20 + camera->GetPosition().y;
		SetAttackRect(rect);
		}
		}
		else if (bFacingUp)
		{
		if (GetCurrentAnimationName() != "PlayerAttackUp")
		SetAnimation("PlayerAttackUp");

		if (GetAttackTimer() < GetAttackResetTime() * 0.05f)
		{
		SGD::Rectangle rect;
		rect.left = GetPosition().x + 20 + camera->GetPosition().x;
		rect.top = GetPosition().y - camera->GetPosition().y;
		rect.right = rect.left + 10 + camera->GetPosition().x;
		rect.bottom = rect.top + 20 - camera->GetPosition().y;
		SetAttackRect(rect);
		}
		else if (GetAttackTimer() < GetAttackResetTime() * 0.1f)
		{
		SGD::Rectangle rect;
		rect.left = GetPosition().x + 20 + camera->GetPosition().x;
		rect.top = GetPosition().y - camera->GetPosition().y;
		rect.right = rect.left + 10 + camera->GetPosition().x;
		rect.bottom = rect.top + 20 - camera->GetPosition().y;
		SetAttackRect(rect);
		}
		else if (GetAttackTimer() < GetAttackResetTime() * 0.2f)
		{
		SGD::Rectangle rect;
		rect.left = GetPosition().x + 20 + camera->GetPosition().x;
		rect.top = GetPosition().y - camera->GetPosition().y;
		rect.right = rect.left + 10 + camera->GetPosition().x;
		rect.bottom = rect.top + 20 - camera->GetPosition().y;
		SetAttackRect(rect);
		}
		else
		{
		SGD::Rectangle rect;
		rect.left = GetPosition().x + 20 + camera->GetPosition().x;
		rect.top = GetPosition().y - camera->GetPosition().y;
		rect.right = rect.left + 10 + camera->GetPosition().x;
		rect.bottom = rect.top + 20 - camera->GetPosition().y;
		SetAttackRect(rect);
		}
		}*/
		if (IsFacingLeft()) // Facing Left
		{
			if (GetCurrentAnimationName() != "PlayerAttackLeft")
				SetAnimation("PlayerAttackLeft");

			float velocity = GetVelocity().x / 10;

			if (GetAttackTimer() < GetAttackResetTime() * 0.05f)
			{
				SGD::Rectangle rect;
				rect.left = GetPosition().x - camera->GetPosition().x - 30;
				rect.top = GetPosition().y - camera->GetPosition().y - 25;
				rect.right = rect.left + 10;
				rect.bottom = rect.top + 30;
				SetAttackRect(rect);
				SetArchDrawPointLoc(SGD::Point{ rect.left + 30, rect.top - 25 });
			}
			else if (GetAttackTimer() < GetAttackResetTime() * 0.1f)
			{
				SGD::Rectangle rect;
				rect.left = GetPosition().x - camera->GetPosition().x - 50 + velocity;
				rect.top = GetPosition().y - camera->GetPosition().y - 40;
				rect.right = rect.left + 10 - velocity;
				rect.bottom = rect.top + 60;
				SetAttackRect(rect);
				SetArchDrawPointLoc(SGD::Point{ rect.left + 25, rect.top - 25 });
			}
			else if (GetAttackTimer() < GetAttackResetTime() * 0.2f)
			{
				SGD::Rectangle rect;
				rect.left = GetPosition().x - camera->GetPosition().x - 40 + velocity;
				rect.top = GetPosition().y - camera->GetPosition().y - 60;
				rect.right = rect.left + 10 - velocity;
				rect.bottom = rect.top + 40;
				SetAttackRect(rect);
				SetArchDrawPointLoc(SGD::Point{ rect.left + 20, rect.top - 25 });
			}
			else
			{
				SGD::Rectangle rect;
				rect.left = GetPosition().x - camera->GetPosition().x - 40;
				rect.top = GetPosition().y - camera->GetPosition().y - 80;
				rect.right = rect.left + 10;
				rect.bottom = rect.top + 20;
				SetAttackRect(rect);
				SetArchDrawPointLoc(SGD::Point{ -50, -50 });
			}

		}
		else if (!IsFacingLeft()) // Facing Right
		{
			if (GetCurrentAnimationName() != "PlayerAttackRight")
				SetAnimation("PlayerAttackRight");

			float velocity = GetVelocity().x / 10;

			if (GetAttackTimer() < GetAttackResetTime() * 0.05f)
			{
				SGD::Rectangle rect;
				rect.left = GetPosition().x - camera->GetPosition().x + 30;
				rect.top = GetPosition().y - camera->GetPosition().y - 25;
				rect.right = rect.left + 10;
				rect.bottom = rect.top + 30;
				SetAttackRect(rect);
				SetArchDrawPointLoc(SGD::Point{ rect.right - 20, rect.top - 25 });
			}
			else if (GetAttackTimer() < GetAttackResetTime() * 0.1f)
			{
				SGD::Rectangle rect;
				rect.left = GetPosition().x - camera->GetPosition().x + 40;
				rect.top = GetPosition().y - camera->GetPosition().y - 40;
				rect.right = rect.left + 10 + velocity;
				rect.bottom = rect.top + 60;
				SetAttackRect(rect);
				SetArchDrawPointLoc(SGD::Point{ rect.right - 20, rect.top - 25 });
			}
			else if (GetAttackTimer() < GetAttackResetTime() * 0.2f)
			{
				SGD::Rectangle rect;
				rect.left = GetPosition().x - camera->GetPosition().x + 50;
				rect.top = GetPosition().y - camera->GetPosition().y - 60;
				rect.right = rect.left + 10 + velocity;
				rect.bottom = rect.top + 40;
				SetAttackRect(rect);
				SetArchDrawPointLoc(SGD::Point{ rect.right - 20, rect.top - 25 });
			}
			else
			{
				SGD::Rectangle rect;
				rect.left = GetPosition().x - camera->GetPosition().x + 40;
				rect.top = GetPosition().y - camera->GetPosition().y - 80;
				rect.right = rect.left + 10;
				rect.bottom = rect.top + 20;
				SetAttackRect(rect);
				SetArchDrawPointLoc(SGD::Point{ -50, -50 });
			}
		}
	}
}

SGD::Point Player::GetSpawnLoc()
{
	return spawnLoc;
}

void Player::SetSpawnLoc(SGD::Point loc)
{
	spawnLoc = loc;
}

void Player::AdjustCamera()
{
	if (GetPosition().x - CAMERA->GetPosition().x < CAMERA_WIDTH_CONSTRAINT	&& CAMERA->GetPosition().x > 0.0f)	// Follow player to the left
		CAMERA->SetPosition(SGD::Point(GetPosition().x - CAMERA_WIDTH_CONSTRAINT, CAMERA->GetPosition().y));
	else if (GetPosition().x > CAMERA->GetPosition().x + SCREEN_WIDTH - CAMERA_WIDTH_CONSTRAINT - 50)			// Follow player to the right
		CAMERA->SetPosition(SGD::Point((GetPosition().x + CAMERA_WIDTH_CONSTRAINT) - SCREEN_WIDTH + 50, CAMERA->GetPosition().y));
	if (GetPosition().y - CAMERA->GetPosition().y < CAMERA_HEIGHT_CONSTRAINT && CAMERA->GetPosition().y > 0.0f)	// Follow player to the up
		CAMERA->SetPosition(SGD::Point(CAMERA->GetPosition().x, (GetPosition().y - CAMERA_HEIGHT_CONSTRAINT)));
	else if (GetPosition().y > CAMERA->GetPosition().y + SCREEN_HEIGHT - CAMERA_HEIGHT_CONSTRAINT - 100)		// Follow player to the down
		CAMERA->SetPosition(SGD::Point(CAMERA->GetPosition().x, ((GetPosition().y + CAMERA_HEIGHT_CONSTRAINT + 100) - SCREEN_HEIGHT)));

	// Prevent CAMERA from moving left of origin
	if (CAMERA->GetPosition().x < 0.0f)
		CAMERA->SetPosition(SGD::Point(0.0f, CAMERA->GetPosition().y));

	// Prevent CAMERA from moving above origin
	if (CAMERA->GetPosition().y < 0.0f)
		CAMERA->SetPosition(SGD::Point(CAMERA->GetPosition().x, 0.0f));

	float bottom = ((GAME->GetTileManager()->GetLevelSize().height * GAME->GetTileManager()->GetTileSize().height) - SCREEN_HEIGHT);
	float end = ((GAME->GetTileManager()->GetLevelSize().width * GAME->GetTileManager()->GetTileSize().width) - SCREEN_WIDTH);

	// Prevent CAMERA from moving right of end
	if (CAMERA->GetPosition().x > end)
		CAMERA->SetPosition(SGD::Point(end, CAMERA->GetPosition().y));

	// Prevent CAMERA from moving below lowest point
	if (CAMERA->GetPosition().y > bottom)
		CAMERA->SetPosition(SGD::Point(CAMERA->GetPosition().x, bottom));


	// Prevent Player from moving left of start screen

	////////////////////////////////////////////////
	// Found Bug Fix ID: 08
	// Implemented by: Cliff Baird
	// Changed position clamp from 0.0f to 2.0f
	////////////////////////////////////////////////
	if (GetPosition().x < 2.0f)
		SetPosition(SGD::Point(2.0f, GetPosition().y));
	////////////////////////////////////////////////
	// End Found Bug Fix ID: 08
	////////////////////////////////////////////////
	if (GetPosition().x > end + SCREEN_WIDTH - 2)
		SetPosition(SGD::Point(end + SCREEN_WIDTH - 2, GetPosition().y));
}
